package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-10-27 16:50
 **/
public class LeetCode240 {

    /*public boolean searchMatrix(int[][] matrix, int target) {
        for (int i = 0; i < matrix.length; i++) {
            for (int i1 = 0; i1 < matrix[i].length; i1++) {
                if (matrix[i][i1] == target) {
                    return true;
                }
            }
        }
        return false;
    }*/


    public boolean searchMatrix(int[][] matrix, int target) {
        for (int i = 0; i < matrix.length; i++) {
            int low = 0;
            int high = matrix[i].length - 1;
            while (low <= high) {
                int avg = low + high >> 1;
                if (matrix[i][avg] == target) {
                    return true;
                } else if (matrix[i][avg] > target) {
                    high = avg - 1;
                } else {
                    low = avg + 1;
                }
            }
        }
        return false;
    }


}
